    package com.edu.bhu.admin.controller.admin;

import java.util.List;

import com.edu.bhu.common.utils.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.edu.bhu.common.annotation.Log;
import com.edu.bhu.common.enums.BusinessType;
import com.edu.bhu.admin.domain.PreVaccination;
import com.edu.bhu.admin.service.IPreVaccinationService;
import com.edu.bhu.common.core.controller.BaseController;
import com.edu.bhu.common.core.domain.AjaxResult;
import com.edu.bhu.common.utils.poi.ExcelUtil;
import com.edu.bhu.common.core.page.TableDataInfo;

/**
 * 疫苗接种Controller
 * 
 * @author yutianyang
 * @date 2022-04-23
 */
@Controller
@RequestMapping("/admin/vaccination")
public class PreVaccinationController extends BaseController
{
    private String prefix = "admin/vaccination";

    @Autowired
    private IPreVaccinationService preVaccinationService;

    @RequiresPermissions("admin:vaccination:view")
    @GetMapping()
    public String vaccination()
    {
        return prefix + "/vaccination";
    }

    @GetMapping("myVaccination")
    public String myVaccination()
    {
        return prefix + "/myVaccination";
    }

    /**
     * 查询疫苗接种列表
     */
    @RequiresPermissions("admin:vaccination:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(PreVaccination preVaccination)
    {
        startPage();
        List<PreVaccination> list = preVaccinationService.selectPreVaccinationList(preVaccination);
        return getDataTable(list);
    }

    /**
     * 查询我的疫苗接种列表
     */
    @RequiresPermissions("admin:vaccination:list")
    @PostMapping("/myList")
    @ResponseBody
    public TableDataInfo myList(PreVaccination preVaccination)
    {
        preVaccination.setUserId(ShiroUtils.getSysUser().getUserId());
        startPage();
        List<PreVaccination> list = preVaccinationService.selectPreVaccinationList(preVaccination);
        return getDataTable(list);
    }

    /**
     * 导出疫苗接种列表
     */
    @RequiresPermissions("admin:vaccination:export")
    @Log(title = "疫苗接种", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(PreVaccination preVaccination)
    {
        List<PreVaccination> list = preVaccinationService.selectPreVaccinationList(preVaccination);
        ExcelUtil<PreVaccination> util = new ExcelUtil<PreVaccination>(PreVaccination.class);
        return util.exportExcel(list, "疫苗接种数据");
    }

    /**
     * 新增疫苗接种
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存疫苗接种
     */
    @RequiresPermissions("admin:vaccination:add")
    @Log(title = "疫苗接种", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(PreVaccination preVaccination)
    {
        preVaccination.setUserId(ShiroUtils.getSysUser().getUserId());
        return toAjax(preVaccinationService.insertPreVaccination(preVaccination));
    }

    /**
     * 修改疫苗接种
     */
    @RequiresPermissions("admin:vaccination:edit")
    @GetMapping("/edit/{detectionId}")
    public String edit(@PathVariable("detectionId") Long detectionId, ModelMap mmap)
    {
        PreVaccination preVaccination = preVaccinationService.selectPreVaccinationByDetectionId(detectionId);
        mmap.put("preVaccination", preVaccination);
        return prefix + "/edit";
    }

    /**
     * 修改保存疫苗接种
     */
    @RequiresPermissions("admin:vaccination:edit")
    @Log(title = "疫苗接种", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(PreVaccination preVaccination)
    {
        return toAjax(preVaccinationService.updatePreVaccination(preVaccination));
    }

    /**
     * 删除疫苗接种
     */
    @RequiresPermissions("admin:vaccination:remove")
    @Log(title = "疫苗接种", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(preVaccinationService.deletePreVaccinationByDetectionIds(ids));
    }
}
